/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package desarrollosoft.ghce.servicio.implementaciones;

import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;

/**
 * Clase auxiliar para libreria iTextpdf.
 * Sirve para escuchar eventos de paginas cuando se crea el documento
 * @author ariel
 */
public class ListenerEventosPagina extends PdfPageEventHelper {
    
    private int numeroPagina;
    
    @Override
    public void onOpenDocument(PdfWriter writer, Document document) {
        numeroPagina = 0;
    }
    
    @Override
    public void onStartPage(PdfWriter writer, Document document) {
        numeroPagina++;
    }
    
    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        ColumnText.showTextAligned(
                writer.getDirectContent(),
                Element.ALIGN_CENTER,
                new Phrase(String.format("Pagina %d", writer.getPageNumber())),
                300f,
                20f, /* antes 62f */
                0
        );
    }
}